//
//  XYJLanguageTableViewCell.m
//  徙游记-01
//
//  Created by hcios on 2017/7/19.
//  Copyright © 2017年 鹿林. All rights reserved.
//

#import "XYJLanguageTableViewCell.h"

#define ContextFont [UIFont ]

@implementation XYJLanguageTableViewCell

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        _translationLab = [[UILabel alloc] init];
        _originLab = [[UILabel alloc] init];
        _seeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _lineView = [[UIView alloc] init];
    }
    return self;
}


-(void)layoutWithTranslationString:(NSString *)translationString originString:(NSString *)originString withIndex:(NSIndexPath *)index{
    CGFloat padding = 15;
    //翻译
    _translationLab.frame = RECT_MAKE(padding, 5, SCREEN_WIDTH, 20);
    _translationLab.text = translationString;
    _translationLab.numberOfLines = 0;
    [_translationLab setFont:[UIFont fontWithName:FONT_NAME_LTH size:13]];
    [self addSubview:_translationLab];
    
    
    //原文
    _originLab.frame = RECT_MAKE(padding, CGRectGetMaxY(_translationLab.frame) + 5, SCREEN_WIDTH, 20);
    _originLab.text = originString;
    _originLab.numberOfLines = 0;
    [_originLab setFont:[UIFont fontWithName:FONT_NAME_LTH size:13]];
    [self addSubview:_originLab];
    
    
    //lineView
    [_lineView setFrame:RECT_MAKE(padding, CGRectGetMaxY(_originLab.frame) + 10, self.frame.size.width - 20, 1)];
    [_lineView setBackgroundColor:[UIColor lightGrayColor]];
    [self addSubview:_lineView];
    
    
    //btn
    [_seeBtn setFrame:RECT_MAKE(10, CGRectGetMaxY(_lineView.frame) + 10, (self.frame.size.width - 10) / 2 - 10, 30)];
    [_seeBtn setTitle:@"查看" forState:UIControlStateNormal];
    [_seeBtn setBackgroundColor:[UIColor cyanColor]];
    _seeBtn.tag = index.row;
    [_seeBtn addTarget:self action:@selector(clickSee:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_seeBtn];
    
    [_deleteBtn setFrame:RECT_MAKE(CGRectGetMaxX(_seeBtn.frame) + 10, CGRectGetMaxY(_lineView.frame) + 10, (self.frame.size.width - 10) / 2 - 10, 30)];
    [_deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
    [_deleteBtn setBackgroundColor:[UIColor redColor]];
    _deleteBtn.tag = index.row;
    [_deleteBtn addTarget:self action:@selector(clickDelete:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_deleteBtn];
}


-(void)clickSee:(id)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(seeCell:)]) {
        [self.delegate seeCell:sender];
    }
}


-(void)clickDelete:(id)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(deleteCell:)]) {
        [self.delegate deleteCell:sender];
    }
}

@end
